package thread;

public class demo20 {
    public static void main(String[] args) {
        Thread t1 = new Thread(()->{
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("t1 end");
        });
        //此次打印先 main 在 t1 在 t2
        //原因在于，谁调用join谁阻塞
        //在本次代码中，t2 调用join 那么t2等待t1运行结束之后在运行
        Thread t2 = new Thread(()->{
            try {
                t1.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("t2 end");
        });

        t1.start();
        t2.start();
        System.out.println("main end");
    }
}
